package com.cbl.v.ssczs.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cbl.v.ssczs.R;
import com.cbl.v.ssczs.mode.entity.LocalDataBean;
import com.cbl.v.ssczs.view.activity.DataListActivity;
import com.google.gson.Gson;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 王凡 on 2017/8/27.
 */

public class StyleHGridAdapter extends MyBaseAdapter<LocalDataBean> {

    public StyleHGridAdapter(Context context, List<LocalDataBean> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.grid_h_layout_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final LocalDataBean bean=dataList.get(position);
        holder.tvTitle.setText(bean.getTitle());
        holder.tvTime.setText(bean.getTime());
        holder.imgLogo.setImageResource(bean.getIcon());
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startNewActivity(DataListActivity.class,new Gson().toJson(bean));
            }
        });
        return convertView;
    }


    class ViewHolder {
        @BindView(R.id.img_logo)
        ImageView imgLogo;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_time)
        TextView tvTime;

        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }


}
